#include "rbtree.hpp"
#include <unistd.h>

namespace bit
{
    using namespace ns_RBTree;

    template <class K>
    class set
    {
    public:
        struct SetKeyOfT
        {
            const K &operator()(const K &k)
            {
                return k;
            }
        };

        typedef typename RBTree<K, K, SetKeyOfT>::iterator iterator;

        std::pair<iterator, bool> insert(const K &key)
        {
            return rb.insert(key);
        }

        iterator Find(const K& key)
        {
            return rb.Find(key);
        }

        iterator begin()
        {
            return rb.begin();
        }

        iterator end()
        {
            return rb.end();
        }

        void Inorder()
        {
            rb.Inorder();
        }

    public:
        RBTree<K, K, SetKeyOfT> rb;
    };

    void test_set()
	{
		set<int> s;
        s.insert(1);
        s.insert(4);
        s.insert(2);
        s.insert(24);
        s.insert(6);
		s.insert(2);
		s.insert(12);
        
        s.Inorder();
		
        auto it = s.begin();
		while (it != s.end())
		{
			std::cout << *it << " ";
			++it;
		}
		std::cout << std::endl;

		set<int> copy(s);
		for (auto e : copy)
		{
			std::cout << e << " ";
		}
		std::cout << std::endl;

		set<int> ss;
		ss.insert(111);
		ss.insert(422);

		copy = ss;
		for (auto e : copy)
		{
			std::cout << e << " ";
		}
		std::cout << std::endl;
	}
}